<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			var ss = [
				{
				  "unique": "4",
				  "menuTitle": "资源管理",
				  "children": [
				    {
				      "unique": "4-1",
				      "menuTitle": "系统设置",
				    },
				    {
				      "unique": "4-2",
				      "menuTitle": "下载管理",
				      "children": [
				        {
				          "unique": "4-2-1",
				          "menuTitle": "图片下载"
				        },
				        {
				          "unique": "4-2-2",
				          "menuTitle": "文件下载"
				        }
				      ]
				    }
				  ]
				}
			];
			var unique = "4-2-1";

			searchUnique(ss, unique)
			transfromRoute(unique)
			function searchUnique(data, unique) {
				let temp = {}
				data.forEach(item => {
					if(item.unique == unique){
						temp = item
					}else if(item.children && item.children.length>0){
						item.children.forEach(i => {
							temp = searchUnique(item.children, unique)
						})
					}
				});
				return temp
			}
			function transfromRoute(unique){
				var unique_arr = [];
				var a1 = unique.split('-')[0];
				var a2 = unique.substring(0,unique.length - unique.indexOf('-') -1);
				unique_arr.push(a1,a2,unique);
				return new Set(unique_arr)
			}
			function result(){
				let arr = []
				let result = []
				transfromRoute(unique).forEach(item => {
					arr.push(searchUnique(ss, item)) 
				})
				arr.forEach(i => {
					result.push(i.menuTitle)
				})
				return result
			}
			console.log(transfromRoute(unique))
			console.log(searchUnique(ss, unique))
			console.log(result())
		</script>
	</head>
	<body>
	</body>
</html>
